/// @tags: Simulate
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>
#include <set>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 1e5 + 2;

int ncnt = 1;
int fa[maxn];
std::set<int> son[maxn];
bool vis[maxn];

int dfs(int u) {
  if (!vis[u]) return u;
  std::vector<int> die;
  int res = -1;
  for (auto i : son[u]) {
    int d = dfs(i);
    if (d != -1) {
      res = d;
      break;
    }
    die.push_back(i);
  }
  for (auto i : die) son[u].erase(i);
  return res;
}

int main() {
  int t;
  cin >> t;
  int ans = 1;
  while (t--) {
    int opt, x;
    cin >> opt >> x;
    if (opt == 1) {
      son[x].insert(++ncnt);
      fa[ncnt] = x;
    } else {
      vis[x] = true;
      while (dfs(ans) == -1) ans = fa[ans];
      ans = dfs(ans);
      cout << ans << '\n';
    }
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("F. Monarchy in Vertigo.in", "r", stdin);
  freopen("F. Monarchy in Vertigo.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
